package com.yanqu.road.logic.activity.zhenhuan;

import com.yanqu.road.entity.activity.ActivityConfig;
import com.yanqu.road.entity.activity.ActivityInfo;
import com.yanqu.road.utils.property.Property;
import com.yanqu.road.utils.property.PropertyHelper;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

public class ZhenHuanThirdProcessConfig {

    private ActivityInfo activityInfo;

    private int exchangeScoreId;       // 兑换积分

    private int energyItemId1;       // 龙灯庆典id
    private int energyItemId2;       // 舞狮庆典id
    private int energyItemId3;       // 花车庆典id

    private String joinReward1;      // 参与龙灯庆典的奖励（新道具格式）
    private List<List<Property>> joinRewardList1 = new ArrayList<>();
    private String joinReward2;      // 参与舞狮庆典的奖励（新道具格式）
    private List<List<Property>> joinRewardList2 = new ArrayList<>();
    private String joinReward3;      // 与花车庆典的奖励（新道具格式）
    private List<List<Property>> joinRewardList3 = new ArrayList<>();

    private int celebrationJoinScore;   // 每位参与庆典的人提供的民心值
    private int celebrationJoinScore2;   // 每位参与庆典的人提供的民心值
    private int celebrationJoinScore3;   // 每位参与庆典的人提供的民心值

    private int celebrationScoreMax1;    // 每场庆典最多的民心值(123634龙灯庆典)
    private int celebrationScoreMax2;    // 每场庆典最多的民心值(123704舞狮庆典)
    private int celebrationScoreMax3;    // 每场庆典最多的民心值(123705花车庆典)

    private int energyItemTime1;         // 龙灯庆典的持续时间（秒）
    private int energyItemTime2;         // 舞狮庆典的持续时间（秒）
    private int energyItemTime3;         // 花车庆典的持续时间（秒）

    private int joinNumberMax;          // 玩家对同一个人的庆典最多看到数量(即对外记录最大数量)

    private int celebrationJoinPeopleMax1; // 当龙灯庆典人数达到配置时可提前结算
    private int celebrationJoinPeopleMax2; // 当舞狮庆典人数达到配置时可提前结算
    private int celebrationJoinPeopleMax3; // 当花车庆典人数达到配置时可提前结算

    public ZhenHuanThirdProcessConfig(ActivityInfo activityInfo, Map<String, ActivityConfig> activityConfigMap) {
        this.activityInfo = activityInfo;
        // 解析下配置
        if (activityConfigMap.containsKey("EXCHANGE_SCORE_ITEM_ID")) {
            this.exchangeScoreId = activityConfigMap.get("EXCHANGE_SCORE_ITEM_ID").getIntValue();
        }
        if (activityConfigMap.containsKey("ZHENHUAN_3_ENERGY_ITEM_ID")) {
            this.energyItemId1 = activityConfigMap.get("ZHENHUAN_3_ENERGY_ITEM_ID").getIntValue();
        }
        if (activityConfigMap.containsKey("ZHENHUAN_3_ENERGY_ITEM_ID_1")) {
            this.energyItemId2 = activityConfigMap.get("ZHENHUAN_3_ENERGY_ITEM_ID_1").getIntValue();
        }
        if (activityConfigMap.containsKey("ZHENHUAN_3_ENERGY_ITEM_ID_2")) {
            this.energyItemId3 = activityConfigMap.get("ZHENHUAN_3_ENERGY_ITEM_ID_2").getIntValue();
        }
        if (activityConfigMap.containsKey("ZHENHUAN_3_JOIN_REWARD")) {
            this.joinReward1 = activityConfigMap.get("ZHENHUAN_3_JOIN_REWARD").getValue();
            this.joinRewardList1 = PropertyHelper.parseNewStringToPropertyList(this.joinReward1);
        }
        if (activityConfigMap.containsKey("ZHENHUAN_3_JOIN_REWARD_1")) {
            this.joinReward2 = activityConfigMap.get("ZHENHUAN_3_JOIN_REWARD_1").getValue();
            this.joinRewardList2 = PropertyHelper.parseNewStringToPropertyList(this.joinReward2);
        }
        if (activityConfigMap.containsKey("ZHENHUAN_3_JOIN_REWARD_2")) {
            this.joinReward3 = activityConfigMap.get("ZHENHUAN_3_JOIN_REWARD_2").getValue();
            this.joinRewardList3 = PropertyHelper.parseNewStringToPropertyList(this.joinReward3);
        }
        if (activityConfigMap.containsKey("ZHENHUAN_3_CELEBRATION_JOIN_SCORE")) {
            this.celebrationJoinScore = activityConfigMap.get("ZHENHUAN_3_CELEBRATION_JOIN_SCORE").getIntValue();
        }
        if (activityConfigMap.containsKey("ZHENHUAN_3_CELEBRATION_JOIN_SCORE_1")) {
            this.celebrationJoinScore2 = activityConfigMap.get("ZHENHUAN_3_CELEBRATION_JOIN_SCORE_1").getIntValue();
        }
        if (activityConfigMap.containsKey("ZHENHUAN_3_CELEBRATION_JOIN_SCORE_2")) {
            this.celebrationJoinScore3 = activityConfigMap.get("ZHENHUAN_3_CELEBRATION_JOIN_SCORE_2").getIntValue();
        }
        if (activityConfigMap.containsKey("ZHENHUAN_3_CELEBRATION_SCORE_MAX")) {
            this.celebrationScoreMax1 = activityConfigMap.get("ZHENHUAN_3_CELEBRATION_SCORE_MAX").getIntValue();
        }
        if (activityConfigMap.containsKey("ZHENHUAN_3_CELEBRATION_SCORE_MAX_1")) {
            this.celebrationScoreMax2 = activityConfigMap.get("ZHENHUAN_3_CELEBRATION_SCORE_MAX_1").getIntValue();
        }
        if (activityConfigMap.containsKey("ZHENHUAN_3_CELEBRATION_SCORE_MAX_2")) {
            this.celebrationScoreMax3 = activityConfigMap.get("ZHENHUAN_3_CELEBRATION_SCORE_MAX_2").getIntValue();
        }
        if (activityConfigMap.containsKey("ZHENHUAN_3_ENERGY_ITEM_TIME")) {
            this.energyItemTime1 = activityConfigMap.get("ZHENHUAN_3_ENERGY_ITEM_TIME").getIntValue();
        }
        if (activityConfigMap.containsKey("ZHENHUAN_3_ENERGY_ITEM_TIME_1")) {
            this.energyItemTime2 = activityConfigMap.get("ZHENHUAN_3_ENERGY_ITEM_TIME_1").getIntValue();
        }
        if (activityConfigMap.containsKey("ZHENHUAN_3_ENERGY_ITEM_TIME_2")) {
            this.energyItemTime3 = activityConfigMap.get("ZHENHUAN_3_ENERGY_ITEM_TIME_2").getIntValue();
        }
        if (activityConfigMap.containsKey("ZHENHUAN_3_JOIN_NUMBER_MAX")) {
            this.joinNumberMax = activityConfigMap.get("ZHENHUAN_3_JOIN_NUMBER_MAX").getIntValue();
        }
        if (activityConfigMap.containsKey("ZHENHUAN_3_CELEBRATION_JOIN_PEOPLE_MAX")) {
            this.celebrationJoinPeopleMax1 = activityConfigMap.get("ZHENHUAN_3_CELEBRATION_JOIN_PEOPLE_MAX").getIntValue();
        }
        if (activityConfigMap.containsKey("ZHENHUAN_3_CELEBRATION_JOIN_PEOPLE_MAX_1")) {
            this.celebrationJoinPeopleMax2 = activityConfigMap.get("ZHENHUAN_3_CELEBRATION_JOIN_PEOPLE_MAX_1").getIntValue();
        }
        if (activityConfigMap.containsKey("ZHENHUAN_3_CELEBRATION_JOIN_PEOPLE_MAX_2")) {
            this.celebrationJoinPeopleMax3 = activityConfigMap.get("ZHENHUAN_3_CELEBRATION_JOIN_PEOPLE_MAX_2").getIntValue();
        }
    }

    public ActivityInfo getActivityInfo() {
        return activityInfo;
    }

    public int getActivityId() {
        return activityInfo.getActivityId();
    }

    public int getExchangeScoreId() {
        return exchangeScoreId;
    }


    public Property randomJoinReward(int goodsId) {
        List<List<Property>> joinRewardList = this.getJoinRewardList(goodsId);
        return PropertyHelper.randomPropertyByListList(joinRewardList);
    }

    public int getEnergyItemId1() {
        return energyItemId1;
    }

    public int getEnergyItemId2() {
        return energyItemId2;
    }

    public int getEnergyItemId3() {
        return energyItemId3;
    }

    public int getCelebrationJoinScore(int openItemId) {
//        return celebrationJoinScore;
        if (openItemId == energyItemId1) {
            return this.celebrationJoinScore;
        }
        if (openItemId == energyItemId2 && this.celebrationJoinScore2 > 0) {
            return this.celebrationJoinScore2;
        }
        if (openItemId == energyItemId3 && this.celebrationJoinScore3 > 0) {
            return this.celebrationJoinScore3;
        }
        return celebrationJoinScore;
    }

    public int getJoinNumberMax() {
        return joinNumberMax;
    }

    public List<List<Property>> getJoinRewardList(int goodsId) {
        if (goodsId == energyItemId1) {
            return this.joinRewardList1;
        }
        if (goodsId == energyItemId2) {
            return this.joinRewardList2;
        }
        if (goodsId == energyItemId3) {
            return this.joinRewardList3;
        }
        return null;
    }

    public int getCelebrationScoreMax(int goodsId) {
        if (goodsId == energyItemId1) {
            return this.celebrationScoreMax1;
        }
        if (goodsId == energyItemId2) {
            return this.celebrationScoreMax2;
        }
        if (goodsId == energyItemId3) {
            return this.celebrationScoreMax3;
        }
        return 0;
    }

    public int getEnergyItemTime(int goodsId) {
        if (goodsId == energyItemId1) {
            return this.energyItemTime1;
        }
        if (goodsId == energyItemId2) {
            return this.energyItemTime2;
        }
        if (goodsId == energyItemId3) {
            return this.energyItemTime3;
        }
        return 0;
    }

    public int getCelebrationJoinPeopleMax(int goodsId) {
        if (goodsId == energyItemId1) {
            return this.celebrationJoinPeopleMax1;
        }
        if (goodsId == energyItemId2) {
            return this.celebrationJoinPeopleMax2;
        }
        if (goodsId == energyItemId3) {
            return this.celebrationJoinPeopleMax3;
        }
        return 0;
    }

    /**
     * 判断开宴道具是否正确
     * @param goodsId
     * @return
     */
    public boolean checkCostItemId(int goodsId) {
        if (goodsId == energyItemId1 || goodsId == energyItemId2 || goodsId == energyItemId3) {
            return true;
        }
        return false;
    }
}
